package com.zxx.coolweather._wuguan;

import android.view.View;

/**
 * 用户请求的统一接口
 *
 * 使用：
 * //Student为自己定义的javaBean
 * Volley.sendJsonRequest(null, url, Student.class, new IDataListener<Student>() {
 *
 * @author zxx on 2022/1/10
 * @Override public void onSuccess(Student student) {
 *         Toast.makeText(MainActivity.this,student.getName(),Toast.LENGTH_SHORT).show();
 *         }
 * @Override public void onFailure() {
 *         Toast.makeText(MainActivity.this,"请求失败",Toast.LENGTH_SHORT).show();
 *         }
 *         });
 */
public class Volley {

    /**
     * @param requestInfo  请求参数
     * @param url          请求地址
     * @param response     请求响应
     * @param dataListener 回调监听
     * @param <T>          参数
     * @param <M>          响应
     */
    public static <T, M> void sendJsonRequest(T requestInfo, String url, String method, Class<M> response, IDataListener<M> dataListener) {
        IHttpRequest httpRequest = new JsonHttpRequest();
        IHttpListener httpListener = new JsonHttpListener<>(response, dataListener);

        HttpTask<T> httpTask = new HttpTask<T>(requestInfo, url, method, httpRequest, httpListener);
        ThreadPoolManager.getInstance().execute(httpTask);
    }


    //使用
    public void onClick(View view) {
        //Student为自己定义的javaBean
        String url = "";
        Volley.sendJsonRequest(null, url, "GET", StudentBean.class, new IDataListener<StudentBean>() {
            @Override
            public void onSuccess(StudentBean student) {

            }

            @Override
            public void onFailure() {

            }
        });
    }


}
